package com.spring.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 添加跨域映射路径
        registry.addMapping("/**")
                // 允许所有域名跨域
                .allowedOrigins("*")
                // 允许所有请求头跨域
                .allowedHeaders("*")
                // 允许GET、POST、DELETE、PUT、OPTIONS、HEAD请求跨域
                .allowedMethods("GET","POST","DELETE","PUT","OPTIONS","HEAD")
                // 预检请求的有效期
                .maxAge(3600);
    }
}
